package backend.project.gym_management.controller;

import backend.project.gym_management.pojo.dto.EnrollmentDTO;
import backend.project.gym_management.service.EnrollmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/enrollments")
public class EnrollmentController {

    @Autowired
    private EnrollmentService enrollmentService;

    @PostMapping
    public ResponseEntity<String> enrollCourse(@RequestParam Long cid, @RequestParam Long uid) {
        enrollmentService.enrollCourse(cid, uid);
        return ResponseEntity.ok("选课成功");
    }

    @GetMapping
    public ResponseEntity<List<EnrollmentDTO>> getEnrollments(@RequestParam Long uid) {
        List<EnrollmentDTO> enrollments = enrollmentService.getEnrollments(uid);
        return ResponseEntity.ok(enrollments);
    }
}
